//
//  TestSafeAreaInsetsViewController.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2023/8/2.
//  Copyright © 2023 moon. All rights reserved.
//

#import "TestSafeAreaInsetsViewController.h"

@interface _TestSafeAreaInsetsViewController_MKUIListView : MKUIListView

@end
@implementation _TestSafeAreaInsetsViewController_MKUIListView

- (UIEdgeInsets)safeAreaInsets{
    UIEdgeInsets insets = [super safeAreaInsets];
//    insets.bottom += 100;
    return insets;
}
@end

@interface  _TestSafeAreaInsetsViewControllerView: UIView

@end
@implementation _TestSafeAreaInsetsViewControllerView

- (UIEdgeInsets)safeAreaInsets{
    UIEdgeInsets insets = [self.superview safeAreaInsets];
//    insets.bottom += 100;
    return insets;
}
@end

@interface TestSafeAreaInsetsViewController ()
@property(nonatomic,strong) MKUIListView *listView;
@end

@implementation TestSafeAreaInsetsViewController
- (id)init{
    if(self=[super init]){
        self.title = @"SafeArea";
        self.tabBarItem.title = self.title;
    }
    return self;
}
- (void)loadView{
    self.view = [_TestSafeAreaInsetsViewControllerView new];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _TestSafeAreaInsetsViewControllerView *v = [_TestSafeAreaInsetsViewControllerView new];
    [self.view addSubview:v];
    self.listView = [[_TestSafeAreaInsetsViewController_MKUIListView alloc] init];
    [self.view addSubview:self.listView];
    for(int i=0;i<20;i++){
        MKUIElementListViewCellDetail *el = [[MKUIElementListViewCellDetail alloc] init];
        el.elementView.titleText = @"test";
        [self.listView addItem:el];
    }
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.listView.frame = self.view.bounds;
    if (@available(iOS 11.0, *)) {
        NSLog(@"listview adjustedContentInset:%@",NSStringFromUIEdgeInsets(self.listView.adjustedContentInset));
        NSLog(@"listview safeAreaInsets:%@",NSStringFromUIEdgeInsets(self.listView.safeAreaInsets));
    }
    if (@available(iOS 11.0, *)) {
        _TestSafeAreaInsetsViewControllerView *v = self.view;
        NSLog(@"TestSafeAreaInsetsViewController safeAreaInsets:%@",NSStringFromUIEdgeInsets(v.safeAreaInsets));
    }
    if (@available(iOS 11.0, *)) {
        _TestSafeAreaInsetsViewControllerView *v = self.view.subviews.firstObject;
        NSLog(@"v safeAreaInsets:%@",NSStringFromUIEdgeInsets(v.safeAreaInsets));
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
